# 登录 注册
from datetime import datetime
from func import check_login, init_login_dict, check_info
from func import save_data, save_flow


def get_name_pwd():
    username = input("用户名：").strip()
    password = input("密码：").strip()
    return username, password


def login():
    username, password = get_name_pwd()
    flag, msg = check_login(username=username, password=password)
    if flag:
        init_login_dict(user=username)
    return flag, msg


def register():
    print("注册系统".center(50, '-'))
    username, password = get_name_pwd()
    check_info(username=username, password=password)
    flag, msg = save_data('pwd', username=username, password=password)
    if flag:
        txt = f"{username}注册成功"
        print(txt)
        save_flow('login', user=username, txt=f"{txt}>>>时间为{datetime.now().strftime('%Y年%m月%d日 %H时%M分%S秒')}")
    return flag, msg
